using System;
using System.Linq;
using ECatalog.Controllers;

namespace ECatalog.Models.Colors
{
    public class ColorRepository : IColorRepository
    {
        public Color Add(Color color)
        {
            using (var db = new DbContainer())
            {
                try
                {
                    db.Colors.Add(color);
                    db.SaveChanges();
                }
                catch (Exception)
                {

                }
                return color;
            }
        }

        public void Remove(int colorid)
        {
            using (var db = new DbContainer())
            {
                var c = db.Colors.SingleOrDefault(st => st.ColorId == colorid);
                if (c != null)
                {
                    try
                    {
                        db.Colors.Remove(c);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
    }
}